package br.com.chat.controller.impl;

import java.io.IOException;
import java.net.ServerSocket;

import br.com.chat.controller.ClienteChat;
import br.com.chat.controller.ServerChat;

public abstract class ConexaoChat {
	private static ServerChat serverChat = getInstanceServer();
    
	public ServerChat getServerChat() {
		return serverChat;
	}

	public static final ServerChat getInstanceServer(){
		ServerChat serverChat = new ServerChatImpl();
		return serverChat;
	}
	
	public static Boolean isServerOnline(){
    	Integer portaServidor = 4242;
    	ServerSocket serverSocket;
    	Boolean isClosed = false;
    	Boolean serverClosed = false;
    	try {
			serverSocket = new ServerSocket(portaServidor);
			isClosed = serverSocket.isClosed();
			if(isClosed){
				serverClosed = true;
			}
    	} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	return serverClosed;
    }
	
//	public static Boolean isClienteOnline(Cliente cliente){
//    	Boolean isOnline = contatos.containsKey(cliente.getEmail());
//    	return isOnline;
//    }
	
//	private static Cliente getClienteOnline(Cliente cliente){
//    	TreeMap<String,Cliente> contatos = new ServerChatImpl().getContatos();
//    	cliente = contatos.get(cliente.getEmail());
//    	return cliente;
//	}
	
//	public static final Cliente getClienteOnline(Cliente cliente){
//		Boolean isOnline = isClienteOnline(cliente);
//		TreeMap<String,Cliente> contatos = serverChat.listaContatos(cliente);
//    	
//		if(isOnline){
//			cliente = contatos.get(cliente.getEmail());
//		}
//		
//		return cliente;
//	}
	public static final ClienteChat getInstanceClient(){
		ClienteChat clienteChat = new ClienteChatImpl();
		return clienteChat;
	}	
	
}
